<template>
  <div>
    <a-modal title="切换项目" v-model="visible" destroyOnClose :maskClosable="false"
      :confirm-loading="confirmLoading" @ok="handleOk">
      <a-row>
        <a-col :span="24">
          <a-form-item label="当前项目" :labelCol="{span:6}" :wrapperCol="{span:16}">
            <ry-select :dataSource="projectList" v-model="projectId" value-key="id"
              label-key="projectName"></ry-select>
          </a-form-item>
        </a-col>
      </a-row>
    </a-modal>
  </div>
</template>
<script>
import { ACCESS_TOKEN } from '@/store/mutation-types'
import Vue from 'vue'

export default {
  components: {},
  data () {
    return {
      projectId: '',
      visible: false,
      confirmLoading: false,
      projectList: []
    }
  },
  created () {
    this.getProjectList()
  },
  methods: {
    open () {
      this.visible = true
    },
    handleOk () {
      this.$get(`${this.$api.upms.upms.byId}/${this.projectId}`).then(res => {
        if (this.isSuccess(res)) {
          // todo 待完善
          const href = res.data.deployUrl
          // const href = 'http://localhost:9001'
          window.location.href = `${href}?token=${Vue.ls.get(ACCESS_TOKEN)}&originAppId=${process.env.APPID}`
        }
      })
    },
    getProjectList () {
      this.$post(this.$api.upms.upms.selectExists).then(res => {
        this.projectList = res.data
      })
    }
  }
}
</script>
<style lang='less'>
</style>
